package com.longrise.bjjt;


import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.baidu.location.Address;
import com.baidu.mapapi.SDKInitializer;


import com.facebook.drawee.backends.pipeline.Fresco;
import com.longrise.LEAP.Base.Encrypt.EncryptService;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.bjjt.util.PrefUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

/**
 * @author Administrator
 * @time 2015-7-15 上午10:50:49
 * @des 定义一个全局的盒子.里面放置的对象,属性,方法都是全局可以调用
 *
 * @version $Rev: 8 $
 * @updateAuthor $Author: admin $
 * @updateDate $Date: 2015-07-15 17:06:45 +0800 (星期三, 15 七月 2015) $
 * @updateDes TODO
 */
public class BaseApplication extends Application
{

	private static Context mContext;
	private static Thread mMainThread;
	private static long mMainTreadId;
	private static Looper mMainLooper;
	private static Handler mHandler;

	// 平台地址
	private String serverUrl;
	// 平台地址
	private String wxServerUrl;

	private String baseServerUrl;
	// 升级地址
	private String updateUrl;
	// areaid
	private String areaid;
	// 经度
	private String longitude;
	// 纬度
	private String latitude;
	// 地址
	private String address;
	// 用户信息对象
	private EntityBean loginInfo;
	// token
	private String token;
	//快处快赔调用服务所需要用的用户名和密码
	private String kckpName;
	private String kckpPass;	
	
	//add by huxin 获取省和市 等信息
	private Address Addressbean;
	
	private String defaultCityCode;


	// =======================get()/set()=========================

	public String getDefaultCityCode() {
		return defaultCityCode;
	}

	public void setDefaultCityCode(String defaultCityCode) {
		this.defaultCityCode = defaultCityCode;
	}

	public String getKckpName()
	{
		return kckpName;
	}

	public void setKckpName(String kckpName)
	{
		this.kckpName = kckpName;
	}

	public String getKckpPass() 
	{
		return kckpPass;
	}

	public void setKckpPass(String kckpPass)
	{
		this.kckpPass = kckpPass;
	}

	public EntityBean getLoginInfo() 
	{
		return loginInfo;
	}

	public void setLoginInfo(EntityBean loginInfo)
	{
		this.loginInfo = loginInfo;
	}
	public String getBaseServerUrl()
	{
		return baseServerUrl;
	}

	public void setBaseServerUrl(String baseServerUrl)
	{
		this.baseServerUrl = baseServerUrl;
	}

	public String getToken()
	{
		return token;
	}

	public void setToken(String token)
	{
		this.token = token;
	}

	public String getWxServerUrl()
	{
		return wxServerUrl;
	}

	public void setWxServerUrl(String wxServerUrl)
	{
		this.wxServerUrl = wxServerUrl;
	}

	public static Context getmContext()
	{
		return mContext;
	}

	public static Thread getmMainThread()
	{
		return mMainThread;
	}

	public static long getmMainTreadId()
	{
		return mMainTreadId;
	}

	public static Looper getmMainLooper()
	{
		return mMainLooper;
	}

	public static Handler getmHandler()
	{
		return mHandler;
	}

	public String getServerUrl()
	{
		return serverUrl;
	}

	public String getUpdateUrl()
	{
		return updateUrl;
	}

	public String getAreaid()
	{
		return areaid;

	}

	public String getLongitude()
	{
		return longitude;
	}

	public String getLatitude()
	{
		return latitude;
	}

	public String getAddress()
	{
		return address;
	}

	public static void setmContext(Context mContext)
	{
		BaseApplication.mContext = mContext;
	}

	public static void setmMainThread(Thread mMainThread)
	{
		BaseApplication.mMainThread = mMainThread;
	}

	public static void setmMainTreadId(long mMainTreadId)
	{
		BaseApplication.mMainTreadId = mMainTreadId;
	}

	public static void setmMainLooper(Looper mMainLooper)
	{
		BaseApplication.mMainLooper = mMainLooper;
	}

	public static void setmHandler(Handler mHandler)
	{
		BaseApplication.mHandler = mHandler;
	}

	public void setServerUrl(String serverUrl)
	{
		this.serverUrl = serverUrl;
	}

	public void setUpdateUrl(String updateUrl)
	{
		this.updateUrl = updateUrl;
	}

	public void setAreaid(String areaid)
	{
		this.areaid = areaid;
	}

	public void setLongitude(String longitude)
	{
		this.longitude = longitude;
	}

	public void setLatitude(String latitude)
	{
		this.latitude = latitude;
	}

	public void setAddress(String address)
	{
		this.address = address;
	}
	
	//add by huxin 获取省和市,等信息
	public Address getAddressbean()
	{
		return Addressbean;
	}

	public void setAddressbean(Address addressbean)
	{
		Addressbean = addressbean;
	}

	
	// =======================get()=========================

	public static Handler getHandler()
	{
		return mHandler;
	}

	public static Context getContext()
	{
		return mContext;
	}

	public static Thread getMainThread()
	{
		return mMainThread;
	}

	public static long getMainTreadId()
	{
		return mMainTreadId;
	}

	public static Looper getMainThreadLooper()
	{
		return mMainLooper;
	}
	
	public EntityBean getKckpRequestBean() {
		EntityBean bean = new EntityBean();
		bean.set("username", kckpName);
		bean.set("password", kckpPass);
		return bean;
	}

	@Override
	public void onCreate()
	{


		
		// ================全局参数初始化====================
		// 平台地址，由外部设置进来
		/*serverUrl = getResources().getString(R.string.serverUrl);
		wxServerUrl = getResources().getString(R.string.wxServerUrl);// 周市委业务地址
		baseServerUrl = getResources().getString(R.string.baseServerUrl);// 周市委基础登录地址
		// 升级地址
		updateUrl = getResources().getString(R.string.updateUrl);*/
		
		// 获取登录信息
		String loginInfoStr = PrefUtils.getString(getApplicationContext(), "loginInfo", null);
		if (null != null && !"".equals(loginInfoStr))
		{
			EntityBean loginInfo = (EntityBean) com.longrise.LEAP.Base.IO.JSONSerializer.getInstance()
					.DeSerialize(loginInfoStr, EntityBean.class);
			if (null != loginInfo)
			{
				EntityBean userInfo = loginInfo.getBean("userinfo");
				this.token = userInfo.getString("token", null);
			}
		}

		kckpName = "110000002000";
		kckpPass = EncryptService.getInstance().MD5Encrypt("888888a");		

		// 程序的入口
		// 初始化化一些.常用属性.然后放到盒子里面来
		// 上下文
		mContext = getApplicationContext();

		// 主线程
		mMainThread = Thread.currentThread();

		// 主线程Id
		mMainTreadId = android.os.Process.myTid();

		// tid thread
		// uid user
		// pid process
		// 主线程Looper对象
		mMainLooper = getMainLooper();

		// 定义一个handler

		mHandler = new Handler();
		super.onCreate();

		//百度地图
		SDKInitializer.initialize(this);
		//初始化imageloader
		ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));

		Fresco.initialize(getApplicationContext());
	}

}
